package meow
/**
 * User domain class.
 */
class Account implements Serializable {
  // 全文検索の対象は，usernameとuserRealNameのみとする
  static searchable = [only:['username', 'userRealName']]
  static transients = ['pass']
  static hasMany = [authorities: Authority]
  static belongsTo = Authority

  // アカウント名に使えないキーワード一覧
  static ngLists = ['register', 'status', 'account', 'login', 'logout', 'search', 'public_timeline']

  /** Username   */
  String username
  /** User Real Name   */
  String userRealName
  /** MD5 Password   */
  String passwd
  /** enabled   */
  boolean enabled = true

  /** description   */
  String description = ''

  /** plain password to create a MD5 password   */
  String pass = '[secret]'

  static constraints = {
    // usernameの条件([0-9a-zA-Z_]で20文字以内)は勝手に設定した
    username(blank: false, unique: true, matches: "[0-9a-zA-Z_]+", maxSize: 20,
             validator: { if (ngLists.contains(it)) ['default.not.unique.message', 'username', it]})
    userRealName(blank: false)
    // passwdの4桁以下はNGも，勝手に決めた
    passwd(validator: { if (it.length() < 4) ['invalid.password'] })
    enabled()
    description(maxSize: 400)
  }
}
